/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.swe.chums.beans;

import java.io.Serializable;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.apache.log4j.Logger;
import org.primefaces.model.chart.PieChartModel;

/**
 *
 * @author cilingir
 */
@ManagedBean(name = "reportBean")
@ViewScoped
public class ReportBean implements Serializable {

    private static Logger log = Logger.getLogger(ReportBean.class);
    private Date startDate;
    private Date endDate;
    private boolean reportRendered = false;
    private int reportID;
    private Map<String, Integer> reportTypes;
    private PieChartModel likeReportModel, commentReportModel, courseReportModel, videoReportModel;

    public ReportBean() {
    }

    /**
     * Submit report
     */
    public void submitReport() {

        log.debug("[ReportBean.submitReport] - started");
        FacesContext context = FacesContext.getCurrentInstance();
        String errorText = "ERROR";
        
//        if (startDate != null && endDate != null) {
//            log.error("[ReportBean.submitReport] startDate can not be later than the end date, startdate: " + startDate + ", endDate: " + endDate);
//            context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, errorText, "Start date is later than the end date"));
//        } else if (startDate != null) {
//        } else if (endDate != null) {
//        } else {
//        }
        

        if (reportID == 0) {
            likeReportModel = new PieChartModel();
            likeReportModel.set("Like1", 5);
            likeReportModel.set("Like2", 7);
            likeReportModel.set("Like3", 2);
            likeReportModel.set("Like4", 1);

        } else if (reportID == 1) {
            commentReportModel = new PieChartModel();
            commentReportModel.set("Comment1", 10);
            commentReportModel.set("Comment2", 22);
            commentReportModel.set("Comment3", 14);
            commentReportModel.set("Comment4", 3);
            commentReportModel.set("Comment5", 15);
            commentReportModel.set("Comment6", 16);
            commentReportModel.set("Comment7", 33);

        } else if (reportID == 2) {
            courseReportModel = new PieChartModel();
            courseReportModel.set("Course1", 2);
            courseReportModel.set("Course2", 5);
            courseReportModel.set("Course3", 6);
            courseReportModel.set("Course4", 8);
            courseReportModel.set("Course5", 3);

        } else if (reportID == 3) {
            videoReportModel = new PieChartModel();
            videoReportModel.set("Video1", 3);
            videoReportModel.set("Video2", 1);
            videoReportModel.set("Video3", 7);
            videoReportModel.set("Video4", 4);
            videoReportModel.set("Video5", 8);

        }

        reportRendered = true;
    }

    /*----Getter Setters---- */
    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public boolean isReportRendered() {
        return reportRendered;
    }

    public void setReportRendered(boolean reportRendered) {
        this.reportRendered = reportRendered;
    }

    public int getReportID() {
        return reportID;
    }

    public void setReportID(int reportID) {
        this.reportID = reportID;
    }

    public Map<String, Integer> getReportTypes() {
        reportTypes = new LinkedHashMap<String, Integer>();
        reportTypes.put("Likes", 0);
        reportTypes.put("Comments", 1);
        reportTypes.put("Courses", 2);
        reportTypes.put("Watched Videos", 3);
        return reportTypes;
    }

    public void setReportTypes(Map<String, Integer> reportTypes) {
        this.reportTypes = reportTypes;
    }

    public PieChartModel getLikeReportModel() {
        return likeReportModel;
    }

    public void setLikeReportModel(PieChartModel likeReportModel) {
        this.likeReportModel = likeReportModel;
    }

    public PieChartModel getCommentReportModel() {
        return commentReportModel;
    }

    public void setCommentReportModel(PieChartModel commentReportModel) {
        this.commentReportModel = commentReportModel;
    }

    public PieChartModel getCourseReportModel() {
        return courseReportModel;
    }

    public void setCourseReportModel(PieChartModel courseReportModel) {
        this.courseReportModel = courseReportModel;
    }

    public PieChartModel getVideoReportModel() {
        return videoReportModel;
    }

    public void setVideoReportModel(PieChartModel videoReportModel) {
        this.videoReportModel = videoReportModel;
    }
    
    
}
